package com.senney.nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @Author lanmengye@outlook.com
 * @Date 2021/1/1 9:43
 */
public class NIOClient {
    public static void main(String[] args) throws Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 6666);
        if(!socketChannel.connect(inetSocketAddress)){
            while (!socketChannel.finishConnect()){
                System.out.println("客户端正在连接...");
            }
        }
        String str = "hello, nio server...";
        socketChannel.write(ByteBuffer.wrap(str.getBytes()));
        System.in.read();

    }
}
